﻿/*
Copyright (c) 2010 Lance Ward
This software is licensed under the MIT license, except where otherwise noted.
For complete license details, refer to license.txt
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using ADNLib;

namespace ADNCanvas
{
//handles drawing of shapes with multiple points that are released by double-click
    public class ToolAnimPath : Tool
    {
        public ToolAnimPath(DrawingToolType toolType)
        {
            this.toolType = toolType;
        }

        public ToolAnimPath() { this.toolType = DrawingToolType.AnimPath; }

        public override void MouseDown(PointF location, System.Windows.Forms.MouseButtons button, int clicks)
        {
            if (currentShape == null)
            {
                CreateShape(selObjects[0].CenterPoint);
                currentShape.AppendPoint(selObjects[0].CenterPoint, true);
            }
            else
            {
                currentShape.AppendPoint(location, false);
            }
        }

        public override void MouseMove(PointF location, System.Windows.Forms.MouseButtons button, int clicks)
        {
            if (currentShape != null)
            {
                currentShape.AppendPoint(location, true);
            }
        }

        public override void MouseUp(PointF location, System.Windows.Forms.MouseButtons button, int clicks)
        {
            base.MouseUp(location, button, clicks);
        }

        public override void MouseDoubleClick(PointF location, System.Windows.Forms.MouseButtons button, int clicks)
        {
            currentShape.AppendPoint(location, false);
            OnShapeComplete(true);
            OnToolComplete(true);

            currentShape = null;
        }

        public override System.Windows.Forms.Cursor GetToolCursor()
        {
            return Cursors.Cross;
        }

        private void CreateShape(PointF startPoint)
        {
            switch (ToolType)
            {
                case DrawingToolType.AnimPath:
                    currentShape = new Motion(MotionType.MotionPath);
                    break;
            }

            currentShape.AppendPoint(startPoint, true);
            currentShape.FillColor = defaultFill.Clone();
            currentShape.LineColor = defaultLine.Clone();
        }
    }
}
